package com.huaxin.device.mapping;

import com.huaxin.device.dto.enums.AlarmLevel;
import com.huaxin.device.dto.enums.AlarmType;
import com.huaxin.device.dto.request.DeviceAlarmCreateReqDTO;
import com.huaxin.device.models.DeviceAlarm;
import com.huaxin.hxenum.enums.DeviceType;
import org.mapstruct.AfterMapping;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.MappingTarget;

@Mapper(componentModel = "spring")
public interface DeviceAlarmMapping {

    @Mapping(target = "deviceType", ignore = true)
    @Mapping(target = "alarmType", ignore = true)
    @Mapping(target = "alarmLevel", ignore = true)
    DeviceAlarm toEntity(DeviceAlarmCreateReqDTO in);

    @AfterMapping
    default void afterMapping(DeviceAlarmCreateReqDTO in, @MappingTarget DeviceAlarm entity) {
        entity.setDeviceType(DeviceType.of(in.getDeviceType()));
        entity.setAlarmType(AlarmType.of(in.getAlarmType()));
        entity.setAlarmLevel(AlarmLevel.of(in.getAlarmLevel()));
    }
}